<!--
 * @Author: Wayne 13235388225@163.com
 * @Date: 2023-10-07 09:18:08
 * @LastEditors: Wayne 13235388225@163.com
 * @LastEditTime: 2023-10-07 17:17:12
 * @FilePath: \Jkc-app-front-new\src\views\refund\refund.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <div class="view-title">返费管理</div>
    <!-- table -->
    <div>
      <el-table
        :data="refundTableData"
        v-loading="loading"
        element-loading-text="正在加载中"
        :header-cell-style="{
          borderColor: '#F0F0F0',
          height: '51px',
          background: '#F0F0F0',
          color: '#333',
        }"
        :row-style="{ height: '51px' }"
        :cell-style="{ borderColor: '#F0F0F0' }"
        style="width: 100%; margin-top: 20px"
      >
        <el-table-column prop="id" label="ID" align="center"> </el-table-column>
        <el-table-column prop="user_id" label="用户id" align="center">
        </el-table-column>
        <el-table-column prop="phone" label="手机号" align="center">
        </el-table-column>
        <el-table-column
          prop="commodity_name"
          label="商品名称"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="order_id" label="订单号" align="center">
        </el-table-column>
        <el-table-column
          prop="status"
          label="返费状态"
          width="120"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0"
              ><el-tag type="warning">返费中</el-tag></span
            >
            <span v-if="scope.row.status == 1"
              ><el-tag type="success">返费成功</el-tag></span
            >
            <span v-if="scope.row.status == 2"
              ><el-tag type="danger">返费失败</el-tag></span
            >
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间" align="center">
        </el-table-column>
        <el-table-column prop="updated_at" label="更新时间" align="center">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="160"
          align="center"
          v-if="false"
        >
          <template slot-scope="scope">
            <el-button
              @click="handleCheck(scope.row)"
              type="text"
              size="small"
              v-if="false"
              >查看</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleExamine(scope.row)"
              v-if="false"
              >审批</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="page_box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNow"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 审批弹窗 -->
    <el-dialog title="审批" :visible.sync="dialogVisibleExamine" width="30%">
      <div class="dialog_examine_box">
        <div>
          <el-select
            v-model="examineValue"
            placeholder="请选择"
            @change="handlerChangeExamine"
          >
            <el-option
              v-for="item in examineOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div v-if="isShowInput">
          <el-input
            v-model="inputExamine"
            placeholder="请输入拒绝理由"
            style="width: 200px; margin-top: 10px"
          ></el-input>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog">取 消</el-button>
        <el-button type="primary" @click="sureDiaolog">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getRefundApplyList, checkRefundApply } from "@/api/refund";
export default {
  name: "Refund",
  data() {
    return {
      refundTableData: [],
      pageNow: 1,
      pageSize: 10,
      total: null,
      dialogVisibleExamine: false,
      examineValue: "",
      examineOptions: [
        {
          value: "1",
          label: "同意",
        },
        {
          value: "2",
          label: "拒绝",
        },
      ],
      inputExamine: "",
      isShowInput: false,
      phoneNum: "",
      loading: true,
    };
  },
  mounted() {
    this.getRefundApplyList();
  },
  methods: {
    // 查询全部返费申请
    getRefundApplyList() {
      getRefundApplyList({
        page_now: this.pageNow,
        page_size: this.pageSize,
      }).then((res) => {
        if (res.code == 1) {
          this.loading = false;
          this.refundTableData = res.data;
          this.total = res.page_info.total_count;
        } else {
          this.loading = false;
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 审批
    checkRefundApply() {
      checkRefundApply({
        phone: this.phoneNum,
        status: this.examineValue,
        reason: this.inputExamine,
      }).then((res) => {
        if (res.code == 1) {
          this.$message.success(res.msg);
          this.dialogVisibleExamine = false;
          this.getRefundApplyList();
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 查看
    handleCheck(val) {},

    // 审批
    handleExamine(val) {
      this.phoneNum = val.phone;
      this.dialogVisibleExamine = true;
    },

    handlerChangeExamine() {
      if (this.examineValue == 2) {
        this.isShowInput = true;
      } else {
        this.isShowInput = false;
      }
    },

    // 弹窗确定
    sureDiaolog() {
      this.checkRefundApply();
    },

    // 弹窗取消
    cancelDialog() {
      this.examineValue = "";
      this.inputExamine = "";
      this.dialogVisibleExamine = false;
    },

    handleSizeChange(val) {
      this.pageSize = val;
      this.pageNow = 1;
      this.getRefundApplyList();
    },
    handleCurrentChange(val) {
      this.pageNow = val;
      this.pageSize = 10;
      this.getRefundApplyList();
    },
  },
};
</script>
<style lang="scss" scoped>
.page_box {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}
</style>
